#include "http.hpp"

void Login(HttpRequest &req, HttpResponse &resp)
{
    std::string hello = "hello " + req.Args();

    // 登录验证
    // 这里没有具体的登录验证接口
    // 直接返回字符串给客户端
    resp.SetCode(200);
    resp.SetHeaders("Content-Length", std::to_string(hello.size()));
    resp.SetHeaders("Content-Type", "text/plain");
    resp.SetText(hello);
}

// httpserver port
int main(int argc, char *argv[])
{
    if(argc != 2){
        std::cerr << "Usage->" << argv[0] << " port" << std::endl;
        exit(USAGE_ERR);
    }

    uint16_t port = std::stoi(argv[1]);
    // 1.创建http服务器
    std::unique_ptr<Httpserver> httpsvr = std::make_unique<Httpserver>(port);
    httpsvr->RegistService("/login", Login);
    httpsvr->Start();

    return 0;
}